#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""写点临时处理数据用的小工具
随用随写 fiaryox
"""
import xlrd
import os


class Tools:
    def __init__(self):
        pass

    # 将写好的诗词标题转换为正确标题的空诗词文件
    def str_to_file(self):
        ex_file = xlrd.open_workbook(r".\诗词大会软件导入诗词目录.xls")
        sheet = ex_file.sheet_by_index(0)
        names = sheet.col_values(4)
        is_in = sheet.col_values(5)
        contents = sheet.col_values(6)

        poetrys = {}
        for i in range(names.__len__()):
            if is_in[i] == 'Y':
                poetrys[names[i]] = contents[i]
                print("【" + names[i] + "】已转换")

        path = r"D:\PoetryFileToXml"
        for item in poetrys:
            file = open(path + "\\" + item, "w")
            file.write(poetrys[item])
            file.close()

    def xml_to_poetry(self):
        list = os.listdir("./poetry_store")
        for item in list:
            if ".xml" in item:
                print(item[7:])
                # os.rename()


if __name__ == "__main__":
    tools = Tools()
    # tools.str_to_file()
    tools.xml_to_poetry()